package com.kitty.web.controller;

import com.kitty.web.controller.BaseController;
import com.kitty.web.common.AjaxResult;
import com.kitty.web.core.page.TableDataInfo;
import com.kitty.web.domain.TAccount;
import com.kitty.web.system.account.service.ITAccountServiceM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 账号管理Controller
 * 
 * @author soul
 * @date 2022-04-21
 */
@Controller
@RequestMapping("/system/account")
public class TAccountController extends BaseController
{
    private String prefix = "system/account";

    @Autowired
    private ITAccountServiceM tAccountServiceM;


    @GetMapping()
    public String account()
    {
        return prefix + "/account";
    }

    /**
     * 查询账号管理列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TAccount tAccount)
    {
        startPage();
        List<TAccount> list = tAccountServiceM.selectTAccountList(tAccount);
        return getDataTable(list);
    }

    /**
     * 新增账号管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账号管理
     */


    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TAccount tAccount)
    {
        return toAjax(tAccountServiceM.insertTAccount(tAccount));
    }

    /**
     * 修改账号管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TAccount tAccount = tAccountServiceM.selectTAccountById(id);
        mmap.put("tAccount", tAccount);
        return prefix + "/edit";
    }
    //封禁账号
    @PostMapping("/stopUserName")
    @ResponseBody
    public AjaxResult stopUserName(TAccount tAccount) {
//        TAccount tAccount = new TAccount();
//        tAccount.setUsername(userName);
        List<TAccount> tAccounts = tAccountServiceM.selectTAccountList(tAccount);
        TAccount tAccount1 = null;

        if(tAccounts.size()>0){
            tAccount1= tAccounts.get(0);
            if(1 == tAccount.getIsstop().intValue()){
                tAccount1.setIsstop(0L);
            }else{
                tAccount1.setIsstop(1L);
            }

        }
        return toAjax(tAccountServiceM.updateTAccount(tAccount1));
    }
    /**
     * 修改保存账号管理
     */


    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TAccount tAccount)
    {
        return toAjax(tAccountServiceM.updateTAccount(tAccount));
    }

    /**
     * 删除账号管理
     */


    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tAccountServiceM.deleteTAccountByIds(ids));
    }



}
